// Includes
#include "BoundingObjects.h"

namespace EraAstral
{
	namespace core
	{
		// 3D bounding sphere default constructor
		BoundingSphere3D::BoundingSphere3D()
			: m_center(0.0f)
		{
			// Set initial parameters
			m_radius = 1.0f;
			
			m_type = BO_SPHERE3D;
		}
		
		// 3D bounding sphere constructor setting paramters
		BoundingSphere3D::BoundingSphere3D(const Vector3& center, float radius)
			: m_center(center)
		{
			m_radius = radius;
			
			m_type = BO_SPHERE3D;
		}
				
		// Check if the object intersects another object
		bool BoundingSphere3D::Intersects(IBoundingObject *object)
		{
			// Check other object's type
			switch (object->GetType())
			{
				// Sphere - sphere intersection
				case BO_SPHERE3D:
					// Intersection if the distance between centers is less than or equal to the combined radius of the two spheres
					return m_center.GetDistance(((BoundingSphere3D *)object)->GetCenter()) <= (m_radius + ((BoundingSphere3D *)object)->GetRadius());
					
				// Sphere - axis aligned box intersection
				case BO_AABOX3D:
					// TODO: Implement sphere - aa box algorithm
					return false;
					
				// Unknown bounding object type
				default:
					return false;
			};
		}
		
		// Returns the center position of the sphere
		Vector3 BoundingSphere3D::GetCenter() const
		{
			return m_center;
		}
		
		// Returns the radius of the sphere
		float BoundingSphere3D::GetRadius() const
		{
			return m_radius;
		}
		
		// 3D axis aligned bounding box default constructor
		BoundingBoxAA3D::BoundingBoxAA3D()
			: m_position(0.0f)
		{
			// Set initial parameters
			m_width = 1.0f;
			m_height = 1.0f;
			m_depth = 1.0f;
			
			m_type = BO_AABOX3D;
		}
		
		// 3D axis aligned bounding box constructor settings parameters
		BoundingBoxAA3D::BoundingBoxAA3D(const Vector3& position, float width, float height, float depth)
			: m_position(position)
		{
			m_width = width;
			m_height = height;
			m_depth = depth;
			
			m_type = BO_AABOX3D;
		}
		
		// Check if the object intersects another object
		bool BoundingBoxAA3D::Intersects(IBoundingObject *object)
		{
			// Check other object's type
			switch (object->GetType())
			{
				// Sphere - sphere intersection
				case BO_SPHERE3D:
					// TODO: Implement aa box - aa box algorithm
					return false;
					
				// Sphere - axis aligned box intersection
				case BO_AABOX3D:
					// TODO: Implement sphere - aa box algorithm
					return false;		
			
				// Unknown bounding object type
				default:
					return false;
			}
		}
		
		// Gets the position of the bounding box
		Vector3 BoundingBoxAA3D::GetPosition() const
		{
			return m_position;
		}
		
		// Gets the width of the bounding box
		float BoundingBoxAA3D::GetWidth() const
		{
			return m_width;
		}
		
		// Gets the height of the bounding box
		float BoundingBoxAA3D::GetHeight() const
		{
			return m_height;
		}
		
		// Gets the depth of the bounding box
		float BoundingBoxAA3D::GetDepth() const
		{
			return m_depth;
		}
	}
}
